class Solution 
{
public:
    int numberOfArithmeticSlices(vector<int>& nums) 
    {
        int n = nums.size();
        if (n < 3)
            return 0;
            
        vector<int> dp(n);
        
        int tmp = nums[1] - nums[0];
        int cnt = 1;
        for (int i = 2; i < n; ++i)
        {
            dp[i] = dp[i - 1];
            
            if (nums[i] - nums[i - 1] == tmp)
                dp[i] += cnt++;
            else
            {
                tmp = nums[i] - nums[i - 1];
                cnt = 1;
            }
        }
        
        return dp[n - 1];
    }
};